package ru.tulupov.producerconsumerpattern;

import java.util.Observable;
import java.util.Random;

public class ToyProducer extends AbstractProducer {
	private final Random random = new Random();

	public ToyProducer(Storage<Playable> storage) {
		super(storage);
	}

	private ToyType randomToyType() {
		final ToyType[] types = { ToyType.DOLL, ToyType.CAR, ToyType.KNIFE };

		return types[random.nextInt(types.length)];
	}

	private Color randomColor() {
		final Color[] colors = { Color.RED, Color.GREEN, Color.BLUE };

		return colors[random.nextInt(colors.length)];
	}

	@Override
	protected Playable onCreate() {

		return new Toy(randomToyType(), randomColor());
	}

	@Override
	public void update(Observable observable, Object obj) {
		interrupt();
	}
}
